<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IFS - 备货预测系统</title>
<link rel="shortcut icon" href="favicon.ico">
<!-- FontAwesome 4.3.0 -->
<link href="{$fonts.url}font-awesome-4.4.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<!-- Ionicons 2.0.1 -->
<link href="{$fonts.url}ionicons-2.0.1/css/ionicons.min.css" rel="stylesheet" type="text/css" />
<!--bootstrap-->
<link href="{$css.url}bootstrap_min.css" rel="stylesheet" type="text/css" />
<!--AdminLTE theme-->
<link href="{$css.url}AdminLTE_min.css" rel="stylesheet" type="text/css" />
<link href="{$css.url}AdminLT_skins/_all-skins.min.css" rel="stylesheet" type="text/css" />
<!--web css-->
<link rel="stylesheet" href="{$css.url}base_setting_min.css">
<!--[if lt IE 9]>
    <script src="{$js.url}plugins/html5shiv.min.js"></script>
    <script src="{$js.url}plugins/respond.min.js"></script>
<![endif]-->
{literal}
<style>
    .uploadify-queue{}
.img-thumbnail{width:50px;height:50px;}
.layer-dialog{display:none;}
</style>
{/literal}
</head>
<body class="skin-blue">
<div class="wrapper">
  <!--引入面包屑-->
  {include file="bread_crumbs.tpl"}
  <section class="base-setting-wrap">
    <div class="row">
      <div class="col-md-12">
        <div class="box">
        <form class="form-horizontal" id="addwarehouse" action="/base/warehouse/addwarehouse">
          <div class="box-body">
            <div class="form-group">
              <label for="cnname" class="col-md-2 control-label">仓库名称:<em class="text-star">*</em></label>
              <div class="col-md-9">
                <input type="text" class="form-control" name="warehouse_name" placeholder="" />
              </div>
            </div>
            <div class="form-group">
              <label for="enname" class="col-md-2 control-label">仓库代码:<em class="text-star">*</em></label>
              <div class="col-md-9">
                <input type="text" class="form-control" name="warehouse_code" placeholder="">
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label">所属事业部:<em class="text-star">*</em></label>
              <div class="col-md-9">
                <select class="form-control" name="dept_id">
                  <option value="-">请选择</option>
                  {$deptHtml}
                </select>
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label">仓库类型:<em class="text-star">*</em></label>
              <div class="col-md-9">
                <select class="form-control" name="type">
                  <option value="-">请选择</option>
                  <option value="1">自主</option>
                  <option value="2">合约</option>
                  <option value="3">公共</option>
                  <option value="4">虚拟仓</option>
                  <option value="5">平台虚拟仓</option>
                </select>
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label">是否发货仓库:<em class="text-star">*</em></label>
              <div class="col-md-9">
                <select class="form-control" name="auto_send">
                  <option value="-">请选择</option>
                  <option value="1">是</option>
                  <option value="0">否</option>
                </select>
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label">是否海外仓:<em class="text-star">*</em></label>
              <div class="col-md-9">
                <select class="form-control" name="is_oversea">
                  <option value="-">请选择</option>
                  <option value="1">是</option>
                  <option value="0">否</option>
                </select>
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label">特采数据审核:<em class="text-star">*</em></label>
              <div class="col-md-9">
              	<span class="radio">
                	<label><input type="radio" name="special_data_examine" value="1" checked />无需审核</label>
                </span>
                <span class="radio">
                	<label><input type="radio" name="special_data_examine" value="2">一级审核</label>
                </span>
                <span class="radio">
                	<label><input type="radio" name="special_data_examine" value="3">二级审核</label>
                </span>
                <span class="radio">
                  <label><input type="radio" name="special_data_examine" value="4">三级审核</label>
                </span>
                <p class="help-block form-group-tips">备注：选择主管审核后，则需要先组长审核再主管审核，如不设置则默认无需审核</p>
               </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label">特采需求审核:<em class="text-star">*</em></label>
              <div class="col-md-9">
	              <span class="radio">
	                	<label><input type="radio" name="special_demand_examine" value="1" checked />无需审核</label>
	               </span>
	               <span class="radio">
	                	<label><input type="radio" name="special_demand_examine" value="2" />需要审核</label>
	               </span>
	               <p class="help-block form-group-tips">备注：此处是指，通过提交的特采数据产生的采购需求是否需要审核，如不设置则默认需要审核；与系统直接产生的采购需求审核流程无关。</p>
               </div>

            </div>
            <div class="form-group">
              <label class="col-md-2 control-label">需求审核:<em class="text-star">*</em></label>
              <div class="col-md-9">
              <span class="radio">
                <label>
                  <input type="radio" name="demand_examine" value="1" id="default_sel" checked /> 无需审核</label>
              </span>
              <span class="radio">
                <label>
                  <input type="radio" name="demand_examine" value="2" id="js_openexame" /> 需要审核</label>
              </span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label">备注:<em class="text-star">*</em></label>
              <div class="col-md-9">
              	  <textarea class="form-control" rows="" cols="" name="comment"></textarea>
              </div>
            </div>
          </div>
          <!-- /.box-body -->
          <div class="box-footer text-center">
            <button type="submit" class="btn btn-primary btn-sm">保存</button>
            <button type="reset" class="btn btn-warning btn-sm">重置</button>
            <a href="javascript:history.go(-1);" class="btn btn-default btn-sm">返回</a> </div>
          <!-- /.box-footer -->
          <!--批量审核 弹窗-->
          <div class="layer-dialog" id="js_batch_check_dialog">
            <div class="pt15 pl15 pr15">
                <table class="table table-bordered no-margin" id="examine_boxes">
                  <tr>
                      <td width="150" class="text-left">
                        <label>
                          <input name="l_leader[auditor]" class="js_select" type="checkbox" value="1">
                          <b>小组长审核：</b>
                        </label>
                      </td>
                      <td class="col-md-9 text-left form-inline">
                          <label>总金额达到 <input type="text" class="form-control" name="l_leader[quota]" placeholder="请输入数字" data-level="小组长" /> 元</label>
                          <label>或数量达到 <input type="text" class="form-control" name="l_leader[maxnum]" placeholder="请输入数字" data-level="小组长" /> 个</label>
                      </td>
                  </tr>
                  <tr>
                      <td width="150" class="text-left">
                        <label>
                          <input name="b_leader[auditor]" class="js_select" type="checkbox" value="2">
                          <b>大组长审核：</b>
                        </label>
                      </td>
                      <td class="col-md-9 text-left form-inline">
                          <label>总金额达到 <input type="text" class="form-control" name="b_leader[quota]" placeholder="请输入数字" data-level="大组长" /> 元</label>
                          <label>或数量达到 <input type="text" class="form-control" name="b_leader[maxnum]" placeholder="请输入数字" data-level="大组长" /> 个</label>
                      </td>
                  </tr>
                  <tr>
                      <td width="150" class="text-left">
                        <label>
                          <input name="director[auditor]" class="js_select" type="checkbox" value="3">
                          <b>主管审核：</b>
                        </label>
                      </td>
                      <td class="col-md-9 text-left form-inline">
                          <label>总金额达到 <input type="text" class="form-control" name="director[quota]" placeholder="请输入数字" data-level="主管" /> 元</label>
                          <label>或数量达到 <input type="text" class="form-control" name="director[maxnum]" placeholder="请输入数字" data-level="主管" /> 个</label>
                      </td>
                  </tr>
                  <tr>
                      <td width="150" class="text-left">
                        <label>
                          <input name="manager[auditor]" class="js_select" type="checkbox" value="4">
                          <b>经理审核：</b>
                        </label>
                      </td>
                      <td class="col-md-9 text-left form-inline">
                          <label>总金额达到 <input type="text" class="form-control" name="manager[quota]" placeholder="请输入数字" data-level="经理" /> 元</label>
                          <label>或数量达到 <input type="text" class="form-control" name="manager[maxnum]" placeholder="请输入数字" data-level="经理" /> 个</label>
                      </td>
                  </tr>
                </table>
            </div>
          </div>
          <input type="hidden" name="is_locked" value="1" />
        </form>
        </div>
      </div>
    </div>
  </section>
</div>
<script src="{$js.url}lib/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="{$js.url}lib/bootstrap.min.js" type="text/javascript"></script>
<script src="{$js.url}warehouse/warehouse.js" type="text/javascript"></script>
<script src="{$js.url}plugins/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
<script src="{$js.url}plugins/layer.js" type="text/javascript"></script>
<script src="{$js.url}common.js"></script>

{literal}
<script>
$('#js_uploadCatImg').uploadify({
    'formData':{
        'timestamp' : '2',
        'token'     : '1'
    },
    'swf':'../js/plugins/uploadify/uploadify.swf',
    'uploader':'../js/plugins/uploadify/uploadify.php',
    'fileTypeExts':'*.jpg; *.png',
    'uploadLimit':1,
    'buttonText':'&nbsp;&nbsp;选择图片', //按钮文字
    'buttonClass':'btn btn-default btn fa fa-plus', //按钮样式
    'removeCompleted' : false,
    'width':101, //按钮宽度
    'height':34, //按钮高度
    'auto':false, //自动上传
    'multi' : false,//
    'checkExisting':true,//检测重复
    //将队列显示框放到指定的容器
    'onSelect' : function(file){
        $("#js_uploadCatImg-queue").appendTo("#js_queenHolder");
    },
    //上传完成回调
    'onUploadSuccess' : function(file, data, response) {
        $("#js_catImgHolder").removeClass("hidden").find("img").attr("src",data.url);
    }
});

/*$('#examine_boxes input[type="checkbox"]').click(function (){});*/

// 审核功能
function examine_select_lock(){
  $('#examine_boxes input[type="checkbox"]').each(function (i){
    if(i != 0){
      $(this).prop('disabled', 'disabled');
    }
  });
}
/**
 * 初始化
 * @return
 */
examine_select_lock();
lockExaminBoxes();
function lockExaminBoxes(){
  var loked = 0;
  $('#examine_boxes input[type="text"]').each(function (i){
    $(this).prop('readonly', true);
    if($(this).val() != ''){
      ++ loked;
    }
  });
}

//勾选小组长审核后，才能勾选大组长审核、主管审核、经理审核
$('.js_select').on('change',function(){
	var thisTr = $(this).parents("tr"),
		index = thisTr.index() +1;
	if($(this).prop('checked')){
		if(index != 4){
			thisTr.next("tr").find('.js_select').prop('disabled',false);
		}

		thisTr.find('input').removeAttr('readonly');
	}else{

		if(index != 4){
			var index_s = index +1,
				nextTr = $('#examine_boxes tr:nth-child(n+'+index_s+')');
			nextTr.find('.js_select').prop('disabled',true).prop('checked',false);
			nextTr.find('input[type="text"]').attr('readonly','').val('');
		}

		thisTr.find('input[type="text"]').attr('readonly','').val('');
	}
});

//点击了“无需审核”后，再点击“需要审核”后，则输入框全部为空
$("#default_sel").on('click',function(){
    $('input[name="l_leader[auditor]"]').trigger('click');
});

function checkExamineInit(){

  var l_leader_quota = Number($('input[name="l_leader[quota]"]').val());
  var l_leader_maxnum = Number($('input[name="l_leader[maxnum]"]').val());
  var b_leader_quota = Number($('input[name="b_leader[quota]"]').val());
  var b_leader_maxnum = Number($('input[name="b_leader[maxnum]"]').val());
  var director_quota = Number($('input[name="director[quota]"]').val());
  var director_maxnum = Number($('input[name="director[maxnum]"]').val());
  var manager_quota = Number($('input[name="manager[quota]"]').val());
  var manager_maxnum = Number($('input[name="manager[maxnum]"]').val());

  //金额或数量不能全为空
  var isStop = false;
  $('.js_select').each(function(i,v){
  	var thisTr = $(v).parents("tr");
  	if($(v).prop('checked')){
  		if(thisTr.find('input[type="text"]').eq(0).val() == '' && thisTr.find('input[type="text"]').eq(1).val() == ''){
  			isStop = true;
		}
  	}
  });
  if(isStop){
  	return '选定了审核人，请填写金额或数量';
  }

  //输入比0大的数字
  var ipt = $("#examine_boxes").find("input[type='text']"),
  	  isError = false;
  $(ipt).each(function(i,v){
  	if($(v).val() != '' && !/^[1-9][0-9]*$/.test($(v).val())){
  		isError = true;
  	}
  });
  if(isError){
  	return '须填写比0大的整数';
  }

  //级别小审核的金额或数量需比级别大审核的小
  var amount = $("input[name$='[quota]']"),
  	  val = [];
  $(amount).each(function(i,v){
  	var ipt_val = $(v).val(),
  		level = $(v).data("level");
  	if(ipt_val != ''){
  		val.push(ipt_val,level);
  	}
  });

  for(var j=0;j<val.length;j++){
  	if(Number(val[j]) >= Number(val[j+2])){
  		return val[j+1]+'设定的审核金额过大';
  		return false;
  	}
  }

  var num = $("input[name$='[maxnum]']"),
  	  val2 = [];
  $(num).each(function(i,v){
  	var num_val = $(v).val(),
  		level2 = $(v).data("level");
  	if(num_val != ''){
  		val2.push(num_val,level2);
  	}
  });

  for(var j=0;j<val2.length;j++){
  	if(Number(val2[j]) >= Number(val2[j+2])){
  		return val2[j+1]+'设定的审核数量过大';
  		return false;
  	}
  }
  return false;
}

$('#js_openexame').click(function (){
  layer.open({
      type:"1",
      title:"需求审核",
      area:["600px","auto"],
      content:$("#js_batch_check_dialog"),
      btn:["确定"],
      yes:function(index){
        /*var index = layer.load(1, {
          shade: [0.1,'#fff'] //0.1透明度的白色背景
        });*/
        // S.submiter($('#examine_select'));
          var checked = checkExamineInit();
		  if(checked != false){
		    layer.msg(checked);
		    return false;
		  }
          layer.close(index);
      },
      end:function(){
      	 if(!$('input[name="l_leader[auditor]"]').prop('checked')){
      	 	$('#default_sel').prop('checked',true);
      	 }
      }
  });
});

//上传按钮
$("#js_uploadBtn").on("click",function(){
    $('#js_uploadCatImg').uploadify('upload', '*')
});

$('#addwarehouse').submit(function (){
  var checked = checkExamineInit();
  if(checked != false){
    layer.msg(checked);
    return false;
  }
  S.submiter($(this), '/base/warehouse/index');
  return false;
});
</script>
{/literal}
</body>
</html>
